<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="zh-CN">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>TOP标签</title>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>

<style type="text/css">
#loading{
	width: 120px; height: 20px;
	background: red;
	display:none;
}
</style>

</head>
<body>

<div id="loading">刷新中。。。</div>

<table id="top">
<tr><th> </th><th>每个K宝的价格(K币)</th><th>挂单数量(K宝)</th></tr>
<tbody id="top-sell">
</tbody>

<tbody id="top-buy">
</tbody>

</table>


<script type="text/javascript">


$(document).ready(function(){

getTop();
var iID=setInterval(getTop, 5000);
	
	function getTop(){
		$.post("bg-top.php",{
				action: 'getTop'
				}, function(xml,textStatus){ 
					addMsg(xml); 
				});
	} //END func getTop
	
	function addMsg(xml){
		var i = 1;
		$("#top-sell").empty();
		$('sell', xml).each(function(){
			var price = $('price',this).text();
			var num = $('num',this).text();
			var msg = '<tr><td>卖'+i+'</td><td>'+price+'</td><td>'+num+'</td></tr>';
			$("#top-sell").prepend( msg );
			i++;
		});

		i = 1;
		$("#top-buy").empty();
		$('buy', xml).each(function(){
			var price = $('price',this).text();
			var num = $('num',this).text();
			var msg = '<tr><td>买'+i+'</td><td>'+price+'</td><td>'+num+'</td></tr>';
			$("#top-buy").append( msg );
			i++;
		});

		
		alert( $("#top").html() );
	} //END func addMsg


	  // 共用这2个全局的ajax事件
	$("#top").ajaxStart(function(){
		$("#top-sell").fadeOut();
		$("#top-buy").fadeOut();
		});
	$("#top").ajaxStop(function(){
		$("#top-sell").fadeIn();
		$("#top-buy").fadeIn();
		});
});
</script>

</body></html>